home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 04 - 1988 / 04.09 Sep 88 / 4d stuff / Source Files / SetSerBuf.p < prev    next >
Encoding:
Text File  |  1988-06-22  |  1.5 KB  |  68 lines  |  [TEXT/MPS ]

  1. Program Ext_SetSerBuf;
  2.  
  3. Uses     MemTypes,QuickDraw,OSIntf,ToolIntf,
  4.     Packintf;
  5. {$D+}
  6. {$R-}    
  7. Var
  8.     BufHandle:Handle;
  9.     PrinterOrModem,NbOfBytes:Integer;
  10.  
  11. procedure SetSerBuf(
  12.     var PrinterOrModem:Integer;
  13.     var BufHandle:Handle;
  14.     var NbOfBytes:Integer);
  15.  
  16. var Error,RefNum:Integer;
  17.  
  18. begin
  19.     {default buffersize of 1024 bytes}
  20.     if NbOfBytes<1 then NbOfBytes:=1024;
  21.     {max buffer size is 32000}
  22.     if NbOfBytes>32000 then
  23.         NbOfBytes:=32000;
  24.     {generate space for the new buffer}
  25.  BufHandle:=NewHandle(Ord4(NbOfBytes));
  26.     {Test for Handle allocation error}
  27.     Error:=MemError;
  28.     if Error=NoErr then
  29.     begin
  30.         {Move Handle out of the way to avoid}
  31.         {fragmentation.}
  32.         MoveHHI(BufHandle);
  33.         {Lock that puppy down}
  34.         HLock(BufHandle);
  35.         {Set Reference Number accordingly.}
  36.         {0 is Printer, 1 is Modem}
  37.         if PrinterOrModem=0 then
  38.             RefNum:=-8    {Printer}
  39.         else
  40.             RefNum:=-6;    {Modem}
  41.         {Reassign the serial port buffer}         Error:=SerSetBuf(RefNum,Ptr(BufHandle^)
  42.           ,Ord(GetHandleSize(BufHandle)));
  43.         {Test for errors from reassignment}
  44.         if Error<>NoErr then
  45.         begin
  46.             {If errors then beep and undo what we}
  47.             {have done.}
  48.             SysBeep(10);
  49.             {Assign the error code to NbOfBytes}
  50.             {so that it is returned}
  51.             NbOfBytes:=Error;
  52.             {Unlock and dispose of buffer}
  53.             HUnLock(BufHandle);              DisposHandle(BufHandle);              BufHandle:=Nil;
  54.         end;        {if Error<>NoErr}
  55.     end        {if Error=NoErr, TRUE}
  56.     else
  57.     begin
  58.         {there was a memory allocation error}
  59.         SysBeep(10);
  60.         NbOfBytes:=Error;
  61.     end;        {if Error=NoErr, FALSE}
  62. end;        {SetSerBuf}
  63.  
  64. Begin
  65.     SetSerBuf(PrinterOrModem,BufHandle,
  66.         NbOfBytes);
  67. End. {Main Block}
  68.